<?php
    
    Class FileUploadView{
    	
		private $UploadFile = "UploadedFile";
		private $Upload = "Upload";
		
		//Function to create a form for uploading files.
		function DoUploadBox(){
			
			return "Upload File: <form action='index.php' method='post' enctype='multipart/form-data'>
<label for='file'>Filename:</label>
<input type='file' name=$this->UploadFile id='file' /> 
<br />
<input type='submit' name=$this->Upload value='Upload' />
</form><br/>";
		}
		
		//Function to create a list of uploaded files
		function ShowFiles(){
			$dir = "UploadedFiles/";
			$ret = "Current Files:<br/>";
			
			if($handle = opendir($dir)) 
				{ 
				    while($file = readdir($handle)) 
				    { 
				        clearstatcache(); 
				        if(is_file($dir.'/'.$file)) 
				            $ret .= "$file <br/>"; 
				    } 
				    closedir($handle); 
				} 
				
				return $ret;
		}	
		
		//Returns the file the user is currently trying to upload
		function GetUploadedFile(){
			if(isset($_FILES["UploadedFile"])){
				return $_FILES["UploadedFile"];
			}
			return null;
		}
		
		//Function to se if the user is trying to upload a file.
		function DidUserUpload(){
			if(isset($_POST[$this->Upload])){
				return true;
			}
			return false;
		}
		
		function AddMessageFileUploaded(){
			return "File Successfully Uploaded<br/>";
		}
		function AddMessageFileUploadFail(){
			return "Unsuccessfull Upload, please try again<br/>";
		}
    }
